#include "QSketchArcCircleAction.h"
#include "Core/MainWindow.h"
#include "Sketch/QSketchManager.h"
#include "Core/TempActorManager.h"

QSketchArcCircleAction::QSketchArcCircleAction(QSketchManager* parent, MainWindow* mainWindow)
	: QSketchCurveAction(parent, mainWindow)
{
}

QSketchArcCircleAction::~QSketchArcCircleAction()
{
}

void QSketchArcCircleAction::StartCreate()
{
	std::cout << "Sketch Arc Circle start create." << std::endl;
}

void QSketchArcCircleAction::OnMouseMove(const gp_Pnt& point)
{
}

void QSketchArcCircleAction::OnLeftDown(const gp_Pnt& point)
{
    if (!bIsStartConfirm)
    {
        m_startPoint = point;
        bIsStartConfirm = true;

		m_startPointActorID = m_mainWindow->GetTempActorManager()->GetUnallocatedActor(0.01);
		m_mainWindow->GetTempActorManager()->SetActorVisible(m_startPointActorID, true, point);
    }
    else if (!bIsEndConfirm)
    {
        m_endPoint = point;
        bIsEndConfirm = true;

		m_endPointActorID = m_mainWindow->GetTempActorManager()->GetUnallocatedActor(0.01);
		m_mainWindow->GetTempActorManager()->SetActorVisible(m_endPointActorID, true, point);
    }
    else
    {
        m_tangentPoint = point;
        Handle(QIVtkSelectionPipeline) actor = m_mainWindow->createArcCircle(m_startPoint, m_tangentPoint, m_endPoint);
		actor->m_featureShape.reset(new FeatureShapeArcCircle(actor->OccShape(), m_startPoint,
			m_tangentPoint, m_endPoint));
        m_sketchManager->m_points[EVertexType::EdgeEndVertex].push_back(m_startPoint);
        m_sketchManager->m_points[EVertexType::EdgeEndVertex].push_back(m_endPoint);
		m_sketchManager->EndCreateSketchCurve(actor);
    }
}

void QSketchArcCircleAction::Reset()
{
	m_mainWindow->GetTempActorManager()->FreeActor(m_startPointActorID);
	m_mainWindow->GetTempActorManager()->FreeActor(m_endPointActorID);

	m_startPoint = gp_Pnt();
    m_endPoint = gp_Pnt();
	m_tangentPoint = gp_Pnt();
	bIsStartConfirm = false;
    bIsEndConfirm = false;
    m_startPointActorID = 255;
    m_endPointActorID = 255;
}
